package com.zbkj.admin.controller.platform.assistant;

import com.zbkj.admin.controller.platform.assistant.service.AssistantQuestionService;
import com.zbkj.common.model.assistant.AssistantQuestion;
import com.zbkj.common.page.CommonPage;
import com.zbkj.common.result.CommonResult;
import com.zbkj.service.assistant.model.request.AssistantQuestionRequest;
import com.zbkj.service.assistant.model.request.AssistantQuestionSearchRequest;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import io.swagger.annotations.Api;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 常用问题表 前端控制器
 */
@Slf4j
@RestController
@RequestMapping("api/admin/platform/assistant/question")
@Api(tags = "客服-常用问题") //配合swagger使用

public class AssistantQuestionController {

    @Autowired
    private AssistantQuestionService assistantQuestionService;

    /**
     * 分页显示常用问题表
     * @param request 搜索条件
     * @author keNan
     * @since 2025-06-11
     */
    @ApiOperation(value = "分页列表") //配合swagger使用
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public CommonResult<CommonPage<AssistantQuestion>>  getList(@Validated AssistantQuestionSearchRequest request) {
        CommonPage<AssistantQuestion> assistantQuestionCommonPage = CommonPage.restPage(assistantQuestionService.getPage(request));
        return CommonResult.success(assistantQuestionCommonPage);
    }

    /**
     * 新增常用问题表
     * @param assistantQuestionRequest 新增参数
     * @author keNan
     * @since 2025-06-11
     */
    @ApiOperation(value = "新增")
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public CommonResult<String> save(@RequestBody @Validated AssistantQuestionRequest assistantQuestionRequest) {
        AssistantQuestion assistantQuestion = new AssistantQuestion();
        BeanUtils.copyProperties(assistantQuestionRequest, assistantQuestion);

        if(assistantQuestionService.save(assistantQuestion)) {
            return CommonResult.success();
        } else {
            return CommonResult.failed();
        }
    }

    /**
     * 删除常用问题表
     * @param id Integer
     * @author keNan
     * @since 2025-06-11
     */
    @ApiOperation(value = "删除")
    @RequestMapping(value = "/delete", method = RequestMethod.GET)
    public CommonResult<String> delete(@RequestParam(value = "id") Integer id) {
        if(assistantQuestionService.removeById(id)) {
            return CommonResult.success();
        } else {
            return CommonResult.failed();
        }
    }

    /**
     * 修改常用问题表
     * @param assistantQuestionRequest 修改参数
     * @author keNan
     * @since 2025-06-11
     */
    @ApiOperation(value = "修改")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public CommonResult<String> update(@RequestBody @Validated AssistantQuestionRequest assistantQuestionRequest) {
        AssistantQuestion assistantQuestion = new AssistantQuestion();
        BeanUtils.copyProperties(assistantQuestionRequest, assistantQuestion);

        if(assistantQuestionService.updateById(assistantQuestion)) {
            return CommonResult.success();
        } else {
            return CommonResult.failed();
        }
    }

    /**
     * 查询常用问题表信息
     * @param id Integer
     * @author keNan
     * @since 2025-06-11
     */
    @ApiOperation(value = "详情")
    @RequestMapping(value = "/info", method = RequestMethod.GET)
    public CommonResult<AssistantQuestion> info(@RequestParam(value = "id") Integer id) {
        AssistantQuestion assistantQuestion = assistantQuestionService.getById(id);
        return CommonResult.success(assistantQuestion);
    }
}



